package com.vastcom.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.vastcom.dao.DepartmentDao;
import com.vastcom.dao.GuadianDao;
import com.vastcom.dao.StuinfoDao;
import com.vastcom.model.Department;
import com.vastcom.model.Guadian;
import com.vastcom.model.Stuinfo;
import com.vastcom.service.ManageService;

/**
 * @author vastcom
 *
 */
@Service
public class ManageServiceImpl implements ManageService {
	
	@Autowired
	private DepartmentDao departmentdao;
	@Autowired
	private StuinfoDao stuinfodao;
	@Autowired
	private GuadianDao guadiandao;
	
	
	
	
	

	@Override
	public boolean addDepartment(Department department) {
		
		try {
			departmentdao.save(department);
			return true;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
		
		
	}

	@Override
	public boolean deleteDepartment(Department department) {
		try {
			departmentdao.delete(department);
			return true;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
		
		
	}

	@Override
	public boolean updateDepartment(Department department) {
		
		
		try {
			departmentdao.update(department);
			return true;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
		
		
	}

	@Override
	public Department getDepartment(Department department) {
		
		return departmentdao.get(department.getDepartmentid());
	}
	
	

	@Override
	public String getDeptNameById(String deptid) {
		List<Department> dl=departmentdao.getHQLZdyAnyP("from Department d where d.departmentid=?", deptid);
		if(dl.size()>0){
			return dl.get(0).getMc();
		}
		return null;
	}

	@Override
	public List<Department> getDepartmentList() {
		
		return departmentdao.getHQLZdy("from Department");
	}

	
//	添加操作
	
	@Override
	public boolean addStuinfo(Stuinfo stuinfo) {
		try {
			stuinfodao.save(stuinfo);
			return true;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();

			return false;
		}
		
	}
//删除操作
	@Override
	public boolean deleteStuinfo(Stuinfo stuinfo) {

		try {
			stuinfodao.delete(stuinfo);
			return true;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
		
		
	}
//修改操作
	@Override
	public boolean updateStuinfo(Stuinfo stuinfo) {
		try {
			stuinfodao.update(stuinfo);
			return true;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
		
		
	}
// 根据主键查询单个对象操作
	@Override
	public Stuinfo getStuinfo(Stuinfo stuinfo) {
		
		return stuinfodao.get(stuinfo.getStuinfoid());
	}

	@Override
	public List<Stuinfo> getStuinfoList() {
		
		return stuinfodao.getHQLZdy("from Stuinfo");
	}
	
	
	
	

	
	@Override
	public List<Stuinfo> getStuinfoList(int start, int num) {
	
		return stuinfodao.getHQLZdy("from Stuinfo", start, num);
	}

	@Override
	public List<Stuinfo> getStuinfoListByClassId(String classid) {
		
		return stuinfodao.getHQLZdyAnyP("from Stuinfo s  where s.bj=?", classid);
	}

	@Override
	public List<Stuinfo> getStuinfoListByDeptid(String deptid) {
		return stuinfodao.getHQLZdyAnyP("from Stuinfo s  where s.yx=?", deptid);
	}

	//添加操作
	@Override
	public boolean addGuadian(Guadian guadian) {
		try {
			guadiandao.save(guadian);
			return true;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
		
		
	}
//删除操作
	@Override
	public boolean deleteGuadian(Guadian guadian) {
		try {
			guadiandao.delete(guadian);
			return true;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
		
		
	}
//修改操作
	@Override
	public boolean updateGuadian(Guadian guadian) {
		try {
			guadiandao.update(guadian);
			return true;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
		
	
	}
//获得单个对象操作
	@Override
	public Guadian getGuadian(Guadian guadian) {
		
		return guadiandao.get(guadian.getGuadianid());
	}

	@Override
	public List<Guadian> getGuadianList() {
		
		return guadiandao.getHQLZdy("from Guadian");
	}

	@Override
	public int CountTableSize(String tablename) {
	
		return 	stuinfodao.getContByentity(tablename);
	}
	
	
	
	
	

}
